<template>
    <view class="container">
        <view class="thumb">
            <image :src="info.products.thumb_cdn" />
        </view>

        <view class="info">
            <view class="validate">
                <view class="icon">
                    <image src="/static/images/validate_active.png"></image>
                </view>
                <view class="txt">
                    您查询的产品是官方正品!
                    <view>请放心使用！</view>
                </view>
            </view>

            <view class="line"></view>

            <view class="list">
                <view class="item">
                    <view class="name">
                        查询次数：
                    </view>
                    <view class="value">
                        {{ info.num }}
                    </view>
                </view>

                <view class="item">
                    <view class="name">
                        您查询的防伪码：
                    </view>
                    <view class="value">
                        {{ info.code }}
                    </view>
                </view>

                <view class="item">
                    <view class="name">
                        首次查询时间：
                    </view>
                    <view class="value">
                        {{ info.query_time_text }}
                    </view>
                </view>

                <view class="item">
                    <view class="name">
                        产品：
                    </view>
                    <view class="value">
                        {{ info.products.name }}
                    </view>
                </view>
            </view>

            <view class="code">
                <image :src="info.query_qrcode_cdn" />
            </view>
        </view>

        <!-- 信息提示 -->
        <u-toast ref="uToast"></u-toast>
    </view>
</template>

<script>
export default {
    data() {
        return {
            code: '',
            business: {},
            info: {}
        }
    },
    methods: {
        async getProductInfo() {
            let params = {
                busid: this.business.id,
                code: this.code
            }

            let result = await uni.$u.http.post('/business/info', params);

            if (result.code === 1) {
                this.info = result.data;
            } else {
                this.$refs.uToast.show({
                    type: 'error',
                    message: result.msg
                })
            }
        }
    },
    //组件预加载前，可接收其他页面传递过来的数据
    onLoad(options) {
        let code = options.code ?? 0;

        let business = uni.getStorageSync('business') ? uni.getStorageSync('business') : {};

        if (code) {
            this.code = code;
        }

        if (Object.getOwnPropertyNames(business).length > 0) {
            this.business = business;
        }

        this.getProductInfo();




    }

}

</script>

<style>
page {
    background-color: #eee;
    padding-bottom: 10px;
}

.container {
    width: 95%;
    margin: 0 auto;
}

.thumb {
    width: 100%;
    height: 280px;
    border-radius: 10px;
    overflow: hidden;
}

.thumb image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.info {
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    margin-top: 10px;
    padding: 0 10px 10px;
}

.info .validate {
    display: flex;
    align-items: center;
    padding: 10px 0 10px 10px;
}

.info .validate image {
    width: 50px;
    height: 50px;
    margin-right: 10px;
}

.info .validate .txt {
    font-size: 14px;
}

.info .validate .txt view {
    font-size: 12px;
    color: #9b9b9a;
    margin-top: 5px;
}

.info .line {
    width: 100%;
    height: 1px;
    background: #ebebeb;
    margin: 0 auto;
    margin-bottom: 10px;
}

.info .list .item {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 10px;
}

.info .list .item .name {
    color: #9b9b9a;
}

.info .code {
    width: 100%;
    height: 280px;
}

.info .code image {
    width: 100%;
    height: 100%;
}
</style>